{% extends "base.html" %}

{% block title %}任务日志 - {{ task_log.task.name }} - 在线跑批系统{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1>任务日志</h1>
    <div>
        <a href="{% url 'task_list' %}" class="btn btn-secondary">
            <i class="fas fa-arrow-left me-1"></i>返回任务列表
        </a>
        <a href="{% url 'run_task' task_log.task.id %}" class="btn btn-primary ms-2">
            <i class="fas fa-redo me-1"></i>再次运行
        </a>
    </div>
</div>

<div class="card mb-4">
    <div class="card-header">
        <h5 class="mb-0">任务信息</h5>
    </div>
    <div class="card-body">
        <div class="row">
            <div class="col-md-6">
                <p><strong>任务名称：</strong> {{ task_log.task.name }}</p>
                <p><strong>服务器：</strong> {{ task_log.task.server.name }} ({{ task_log.task.server.hostname }})</p>
                <p><strong>执行人：</strong> {{ task_log.started_by.username }}</p>
            </div>
            <div class="col-md-6">
                <p><strong>状态：</strong>
                    {% if task_log.status == 'running' %}
                        <span class="badge bg-warning">运行中</span>
                    {% elif task_log.status == 'completed' %}
                        <span class="badge bg-success">已完成</span>
                    {% elif task_log.status == 'failed' %}
                        <span class="badge bg-danger">已失败</span>
                    {% endif %}
                </p>
                <p><strong>开始时间：</strong> {{ task_log.started_at|date:"Y-m-d H:i:s" }}</p>
                <p><strong>完成时间：</strong> 
                    {% if task_log.completed_at %}
                        {{ task_log.completed_at|date:"Y-m-d H:i:s" }}
                    {% else %}
                        <span class="text-muted">未完成</span>
                    {% endif %}
                </p>
                <p><strong>执行时长：</strong> {{ task_log.duration }}</p>
            </div>
        </div>
        <div class="mt-3">
            <p><strong>执行命令：</strong></p>
            <pre class="bg-light p-3 rounded">{{ task_log.task.command }}</pre>
        </div>
    </div>
</div>

<div class="card mb-4">
    <div class="card-header">
        <h5 class="mb-0">命令输出</h5>
    </div>
    <div class="card-body">
        {% if task_log.output %}
            <pre class="bg-light p-3 rounded">{{ task_log.output }}</pre>
        {% else %}
            <p class="text-muted">没有命令输出</p>
        {% endif %}
    </div>
</div>

{% if task_log.error %}
    <div class="card">
        <div class="card-header bg-danger text-white">
            <h5 class="mb-0">错误信息</h5>
        </div>
        <div class="card-body">
            <pre class="bg-light p-3 rounded text-danger">{{ task_log.error }}</pre>
        </div>
    </div>
{% endif %}
{% endblock %}
